package myJs.tool

import myJs.myPkg.ResizableOptions
import myJs.myPkg.jquery._
import myJs.Implicits._
import myJs.myPkg.reactHookForm.FormStateRT
import org.scalajs.dom.{Element, Event}

import scala.scalajs.js

/**
 * Created by yz on 7/9/2022
 */
trait FeatureSelectionTool {

  def rightResizable = {
    val rightResizeOptions = ResizableOptions.resizeWidth(true).resizeHeight(false).
      handleSelector(".rightHandler,.rightDrag").
      onDrag(rightDrag).resizeWidthFrom("left")
    $("#right").resizable(rightResizeOptions)
  }

  def rightDrag: js.Function = (e: Event, y: Element, newWidth: Double, newHeight: Double, opt: ResizableOptions) => {
    val rowWidth = $(y).parents(".row").css("width").px2Double
    val minWidth = rowWidth * 0.1
    val maxWidth = rowWidth * 0.4
    if (newWidth <= minWidth || newWidth >= maxWidth) {
      false
    } else {
      val centerWidth = rowWidth * 0.99 - $("#left").width() - newWidth
      $("#center").width(centerWidth)
      true
    }
  }



}
